package com.apps.epocket.config;

import able.guice.AbleModule;
import com.apps.epocket.quartz.GuiceJobFactory;
import com.apps.epocket.quartz.SchedulerManager;
import com.apps.epocket.stripes.PocketStripesModule;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.te.cob.config.PocketConfiguration;
import java.util.Properties;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.JobFactory;



public class PocketModule extends AbleModule {
    public PocketModule() {
        super(new PocketConfiguration(), new PocketStripesModule());
    }

    @Override
    public void configure(Binder binder) {
        super.configure(binder);
        binder.bind(Session.class).toProvider(new Provider<Session>() {

            public Session get() {
                String smtpHost = "mail.theta-edge.com";
                
                Properties props = System.getProperties();
                props.put("mail.smtp.host", smtpHost);               
                
                return Session.getInstance(props, null);
            }

        });
        binder.bind(JobFactory.class).to(GuiceJobFactory.class);
        binder.bind(Scheduler.class).toProvider(new Provider<Scheduler>() {

            @Inject JobFactory jobFactory;

            public Scheduler get() {
                try {
                    Scheduler sc = StdSchedulerFactory.getDefaultScheduler();
                    sc.setJobFactory(jobFactory);
                    return sc;
                } catch (SchedulerException ex) {
                    throw new RuntimeException(ex);
                }
            }
            
        });
        binder.bind(SchedulerManager.class);
        
    }
}
